package com.chj.leetcode.tijie150to200;

public class Code198_HouseRobber {
	public int rob(int[] A) {
		int n = A.length;
		if (n == 0) {
			return 0;
		}

		if (n == 1) {
			return A[0];
		}

		int[] f = new int[n + 1];
		f[0] = 0;
		f[1] = A[0];
//		f[2] = Math.max(A[0], A[1]);
		for (int i = 2; i <= n; i++) {
			f[i] = Math.max(f[i - 1], f[i - 2] + A[i - 1]);
		}

		return f[n];

	}
}
